package com.mybatisPlus.Utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class CodeUtils {
    //生成代码包结构
    public static void main(String[] args) {
        String property = System.getProperty("user.dir");
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC", "root", "Abc20020217!")
                .globalConfig(builder -> {
                    builder.author("liHeWei") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir(property+"/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    Map<OutputFile,String> packageMap=new HashMap<>();
                    packageMap.put(OutputFile.xml, property+"/src/main/resources/mapper");
                    packageMap.put(OutputFile.mapper,property+"/src/main/java/com/mybatisPlus/dao/mapper");
                    packageMap.put(OutputFile.entity,property+"/src/main/java/com/mybatisPlus/dao/entity");
                    packageMap.put(OutputFile.service,property+"/src/main/java/com/mybatisPlus/dao/service");
                    packageMap.put(OutputFile.serviceImpl,property+"/src/main/java/com/mybatisPlus/dao/service/impl");
                    builder.parent("com") // 设置父包名
                            .moduleName("mybatisPlus.dao") // 设置父包模块名
                            .pathInfo(packageMap);

                })
                .strategyConfig(builder -> {
                    builder.addInclude("user","file");// 设置需要生成的表名
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableLombok(); //开启lombok
                } )
                .execute();
    }
}
